package 创建型设计模式.建造者模式.demo;

/**
 * @Author lf
 * @Date 3/27/2024
 */
public class Computer {
    private String CPU;
    private String GPU;
    private String memory;
    private String storage;

    private Computer(Builder builder) {
        this.CPU = builder.CPU;
        this.GPU = builder.GPU;
        this.memory = builder.memory;
        this.storage = builder.storage;
    }

    public static class Builder {
        private String CPU;
        private String GPU;
        private String memory;
        private String storage;

        public Builder CPU(String CPU) {
            this.CPU = CPU;
            return this;
        }

        public Builder GPU(String GPU) {
            this.GPU = GPU;
            return this;
        }

        public Builder memory(String memory) {
            this.memory = memory;
            return this;
        }

        public Builder storage(String storage) {
            this.storage = storage;
            return this;
        }

        public Computer build() {
            return new Computer(this);
        }
    }
    @Override
    public String toString() {
        return "Computer{" +
                "CPU='" + CPU + '\'' +
                ", GPU='" + GPU + '\'' +
                ", memory='" + memory + '\'' +
                ", storage='" + storage + '\'' +
                '}';
    }

    public static void main(String[] args) {
        Computer intelCoreI7 = new Computer.Builder()
                .CPU("Intel Core i7")
                .GPU("NVIDIA RTX 3080")
                .memory("16GB DDR4")
                .storage("1TB SSD")
                .build();
        System.out.println(intelCoreI7.toString());
    }
}
